// DockView.cpp: implementation of the CDockView class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DockPPRetView.h"
#include "../resource.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 CEdit CDockLoggingWnd::m_Edit;

CTabCtrl CDockLoggingWnd::m_tabctrl;
CImageList CDockLoggingWnd::m_ImgList;

//IMPLEMENT_DYNCREATE(CDockPPRetView,baseCDockingResultView);
BEGIN_MESSAGE_MAP(CDockLoggingWnd, baseCDockingResultView)
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_SHOWWINDOW()
ON_NOTIFY(TCN_SELCHANGE, 102, OnTabSelChange)
END_MESSAGE_MAP()
CDockLoggingWnd::CDockLoggingWnd()
{
	
}

CDockLoggingWnd::~CDockLoggingWnd()
{
	
}

int CDockLoggingWnd::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
	if (baseCDockingResultView::OnCreate(lpCreateStruct) == -1)
		return -1;
	CRect rect;
	m_tabctrl.Create(WS_VISIBLE | WS_CHILD | TCS_BOTTOM  , 
		rect, this, 102);
	
	m_ImgList.Create(IDB_TAB, 16, 1, RGB(255,0,255));
	
	m_tabctrl.SetImageList(&m_ImgList);
	
	// set "normal" GUI-font
	CFont *font = CFont::FromHandle((HFONT)::GetStockObject(DEFAULT_GUI_FONT));
	m_tabctrl.SetFont(font);

	m_Edit.Create(WS_BORDER | WS_CHILD | ES_MULTILINE | ES_AUTOHSCROLL|ES_AUTOVSCROLL ,
		rect, &m_tabctrl, 500);
	

	TC_ITEM tci;

	tci.mask = TCIF_TEXT | TCIF_IMAGE;
	tci.pszText = (LPTSTR)(LPCTSTR)"Command Lines";
	tci.iImage = 2;
	m_tabctrl.InsertItem(0, &tci);
	
	return 0;
	
}
void CDockLoggingWnd::OnShowWindow( BOOL bShow, UINT nStatus )
{
	m_tabctrl.SetCurSel(0);
	m_Edit.ShowWindow(SW_SHOW);
}


void CDockLoggingWnd::OnSize( UINT nType, int cx, int cy )
{
	baseCDockingResultView::OnSize(nType, cx, cy);
	
	int bottom = (IsFloating() || IsFloating()) ? cy - 7 : cy - 9;
	m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
	CRect rect, rect1,rect2,rect3,rect4;
	m_tabctrl.GetClientRect(&rect);
	m_Edit.MoveWindow(9,9, rect.right - 18, rect.bottom - rect3.Height() - 9 - 9);
}
void CDockLoggingWnd::AddToDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rt;
	m_Edit.GetClientRect(&rt);
	m_Edit.ShowWindow(SW_SHOW);
	pDrawBar->AddButton(" Edit View ", DRAWBTNSTYLE_GROUP, &m_Edit, &m_tabctrl, &rt, this, 0);
};

void CDockLoggingWnd::RemoveFromDrawBar(CAutoHideBar * pDrawBar)
{
	CRect rt;
	pDrawBar->RemoveButton(&m_Edit);
	pDrawBar->Shrink();
	pDrawBar->CalcLayout();
	pDrawBar->Invalidate();
	GetParentFrame()->ShowControlBar(this, TRUE, FALSE);
	
	m_tabctrl.GetWindowRect(&rt);
	m_tabctrl.SetCurSel(0);
	m_Edit.ShowWindow(SW_SHOW);
	
	GetClientRect(&rt);
	int cx = rt.Width();
	int cy = rt.Height();
	// TODO: Add your message handler code here
	int bottom = IsFloating() ? cy - 7 : cy - 9;
	
	m_tabctrl.MoveWindow(7, 7, cx - 14, bottom);
	CRect rect, rect1,rect2,rect3,rect4;
	m_tabctrl.GetClientRect(&rect);
	m_tabctrl.GetItemRect(0, &rect1);
	m_tabctrl.GetItemRect(1, &rect2);
	m_Edit.MoveWindow(6,6, rect.right - 12, rect.bottom - rect1.Height() - 6 - 6);

};

afx_msg void CDockLoggingWnd::OnTabSelChange(NMHDR* pNMHDR, LRESULT* pResult)
{	
	int Sel = m_tabctrl.GetCurSel();
	m_Edit.ShowWindow(Sel == 0?SW_SHOW:SW_HIDE);
	
}

HWND CDockLoggingWnd::GetEditHwnd()
{
	return m_Edit.GetSafeHwnd();
}
